package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.bdt.api.base.dto.resp.VesselNameDataRespDTO;
import com.cmc.cloud.cmclink.doc.constants.ApprovePermissionConfigConstans;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.ApprovePermissionConfigConvert;
import com.cmc.cloud.cmclink.doc.rpcservice.NucTransferService;
import com.cmc.cloud.cmclink.doc.service.ApprovePermissionConfigService;
import com.cmc.cloud.cmclink.doc.vo.special.approvepermissionvo.ApprovePermissionConfigRespVO;
import com.cmc.cloud.cmclink.doc.vo.special.approvepermissionvo.ApprovePermissionConfigUpdateReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.approvepermissionvo.ApprovePermissionReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.approvepermissionvo.UserWithApprovePermissionRespVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.platform.system.nuc.dto.UserProfileDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 用户船舶审批权限配置前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 用户船舶审批权限配置")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/special/approve-permission-config")
public class ApprovePermissionConfigController {

    @Resource
    private ApprovePermissionConfigService approvePermissionConfigService;

    @Resource
    private NucTransferService nucTransferService;

    @Operation(summary = "更新用户船舶审批权限配置")
    @PostMapping("/update")
    public CommonResult<String>
    updateApprovePermissionConfig(@Valid @RequestBody ApprovePermissionConfigUpdateReqVO updateReqVO) {
        approvePermissionConfigService.updateApprovePermissionConfig(updateReqVO);
        return CommonResult.success(ApprovePermissionConfigConstans.PERMISSION_ENABLE);
    }

    @Operation(summary = "获得除用户之外所有船舶审批权限配置")
    @PostMapping("/get/all/except-user")
    @UseResponsePropertyAdvice
    public CommonResult<List<ApprovePermissionConfigRespVO>> getApprovePermissionConfigWithoutUser(@RequestBody ApprovePermissionReqVO reqVo) {
        List<VesselNameDataRespDTO> vesselNameDataRespDTOList =
                approvePermissionConfigService.getApprovePermissionConfigWithoutUser(reqVo);
        return CommonResult.success(ApprovePermissionConfigConvert.INSTANCE.convertVesselList(vesselNameDataRespDTOList));
    }

    @Operation(summary = "获得用户船舶审批权限配置")
    @PostMapping("/get/user")
    @UseResponsePropertyAdvice
    public CommonResult<UserWithApprovePermissionRespVO> getApprovePermissionConfigWithUser(@RequestBody ApprovePermissionReqVO reqVo) {
        UserWithApprovePermissionRespVO userRespVOList =
                approvePermissionConfigService.getApprovePermissionConfigWithUser(reqVo);
        return CommonResult.success(userRespVOList);
    }

    @Operation(summary = "设置用户审批非自营船权限")
    @PostMapping("/setNonOwnedShip")
    public CommonResult<Void> setNonOwnedShip(@RequestBody ApprovePermissionReqVO reqVo) {
        approvePermissionConfigService.setNonOwnedShip(reqVo);
        return CommonResult.success();
    }



    @Operation(summary = "删除用户船舶审批权限配置")
    @PostMapping("/delete")
    public CommonResult<String> deleteApprovePermissionConfig(@Valid @RequestBody ApprovePermissionConfigUpdateReqVO updateReqVo) {
        approvePermissionConfigService.deleteApprovePermissionConfig(updateReqVo);
        return CommonResult.success(ApprovePermissionConfigConstans.PERMISSION_REVOKE);
    }

    @Operation(summary = "获得当前用户名称")
    @GetMapping("/current/user-name")
    public CommonResult<String> getCurrentUserName() {
        UserProfileDTO userProfileDTO = nucTransferService.getUserProfile();
        return CommonResult.success(userProfileDTO.getUsername());
    }

}
